package cn.ffcs.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnection
{
    
    public void getConnection()
    {
        return;
    }
    
    public String getResult(String sql)
    {
        Connection conn = null;
        try
        {
            Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
            conn = DriverManager.getConnection("proxool.oracle");
//            if (conn != null) System.out.println("数据库连接测试成功！");
            Statement stmt = conn.createStatement();
            ResultSet rst = null;
            rst = stmt.executeQuery(sql); // sql 查询语句，视具体情况而定
            while (rst.next())
                return rst.getString(1);
        }
        catch (SQLException e)
        {
            System.out.print(e.toString());
        }
        catch (Exception ee)
        {
            System.out.print(ee.toString());
        }
        finally
        {
            try
            {
                if (conn != null) conn.close();
            }
            catch (SQLException e2)
            {
                System.out.print(e2.toString());
            }
        }
        return null;
    }
    
    public String getUser(String userId,String misKey){
        String sql="select person from t_secu_user a where a.user_id='"+userId+"' and a.mis_key='"+misKey+"' and a.end>sysdate";
        return getResult(sql);
    }
    
    public int getNum(String person){
        //String sql="select a.num+b.num num1 from (select count(*) num from t_bpm_transactor t where t.userid='"+person+"' and t.end>sysdate) a,";
        //sql+="(select count(*) num from t_poc_req_adv_list a where (a.tran_status_='NEW' or a.tran_status_='REFUSE') and a.end_>sysdate and a.start_user_='"+person+"') b";
        
    	//String sql="select count(*) from t_bpm_proc_tran_record t where t.transactor='"+person+"' and t.state='active'";
    	
    	String sql="select count(*) from v_flow_app_task t where t.userId='"+person+"' and t.state='active'";
    	System.out.println(sql);
    	try{
            return new Integer(getResult(sql)).intValue();
        }catch(Exception e){
            return 0;
        }
    }
    

}
